﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;
using digitwhu.Models.IRepositorys;

namespace digitwhu.Models.Repositorys
{
    public class Repository<T> : IRepository<T> where T : class
    {
        public DataContext context;
        public Repository(DataContext context)
        {
            this.context = context;
        }
        public IEnumerable<T> FindAll(Func<T, bool> exp)
        {
            return context.GetTable<T>().Where(exp);
        }
        public void Add(T entity)
        {
            context.GetTable<T>().InsertOnSubmit(entity);
        }
        public void Delete(T entity)
        {
            context.GetTable<T>().DeleteOnSubmit(entity);
        }
        public void Save()
        {
            context.SubmitChanges();
        }
    }
}